package com.kobeliu.controller;

import com.kobeliu.enums.InterviewStatusEnum;
import com.kobeliu.pojo.Interview;
import com.kobeliu.pojo.bo.CreateInterviewBO;
import com.kobeliu.result.GraceJSONResult;
import com.kobeliu.service.InterviewService;
import com.kobeliu.service.impl.InterviewServiceImpl;
import com.kobeliu.utils.PagedGridResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping("/interview")
@Slf4j
public class InterviewController {

    @Autowired
    private InterviewService interviewService;

    @PostMapping("create")
    public GraceJSONResult create(@RequestBody @Valid CreateInterviewBO bo){

        String interviewId = interviewService.create(bo);

        return GraceJSONResult.ok(interviewId);
    }

    @PostMapping("detail")
    public GraceJSONResult detail(String interviewId,String hrUserId,String companyId){

        Interview interview = interviewService.detail(interviewId,hrUserId,companyId);
        return GraceJSONResult.ok(interview);
    }

    @PostMapping("cancel")
    public GraceJSONResult cancel(String interviewId){

        interviewService.updateInterviewStatus(interviewId, InterviewStatusEnum.CANCEL);
        return GraceJSONResult.ok();
    }

    @PostMapping("accept")
    public GraceJSONResult accept(String interviewId){
        interviewService.updateInterviewStatus(interviewId, InterviewStatusEnum.ACCEPT);
        return GraceJSONResult.ok();
    }

    @PostMapping("refuse")
    public GraceJSONResult refuse(String interviewId){
        interviewService.updateInterviewStatus(interviewId, InterviewStatusEnum.REFUSE);
        return GraceJSONResult.ok();
    }


    @PostMapping("listOfHr")
    public GraceJSONResult listOfHr(String hrId,String companyId,Integer page,Integer limit){
        if(page == null) page=1;
        if(limit == null) limit=10;
        PagedGridResult result = interviewService.listOfHr(hrId,companyId, page,limit);
        return GraceJSONResult.ok(result);
    }

    @PostMapping("listOfCand")
    public GraceJSONResult listOfCand(String candUserId,Integer page,Integer limit){
        if(page == null) page=1;
        if(limit == null) limit=10;
        PagedGridResult result = interviewService.listOfCand(candUserId, page,limit);
        return GraceJSONResult.ok(result);
    }
}
